package com.church.action;

import java.util.Map;

import com.church.db.Tasklist;
import com.church.services.TasklistServices;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class AddTask extends ActionSupport {
	private TasklistServices tasklistServices;
	private String response;
	private Tasklist tasklist;

	public TasklistServices getTasklistServices() {
		return tasklistServices;
	}

	public void setTasklistServices(TasklistServices tasklistServices) {
		this.tasklistServices = tasklistServices;
	}

	public Tasklist getTasklist() {
		return tasklist;
	}

	public void setTasklist(Tasklist tasklist) {
		this.tasklist = tasklist;
	}

	public String getResponse() {
		return response;
	}

	public void setResponse(String response) {
		this.response = response;
	}

	public String execute() {
		System.out.println("####GROUP=");
		ActionContext actionContext = ActionContext.getContext();
		Map session = actionContext.getSession();
		String userGroup = (String) session.get("USER_GROUP");
		String userType=(String) session.get("USER_TYPE");
		System.out.println("####GROUP="+tasklist.getGroup());
		System.out.println("####WORK="+tasklist.getWork());
		if (userGroup != null&&userType!=null) {
			if (userType.equals("admin")) {
				tasklist.setState("0");
				
				if(tasklist.getGroup().length()<1)
				{
					tasklist.setGroup(userGroup);
				}
				tasklistServices.addTask(tasklist);
			}
		}
		return "success";
	}
}
